/* eslint-disable no-useless-escape */
import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index'

import 'tailwindcss/tailwind.css'
import 'ant-design-vue/dist/antd.less'
import './style/main.less'
import './style/antdv.less'
import './utils/theme/antDesignConfig'
// import './assets/iconfont/iconfont.css'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { useInfoStore } from './store'
import 'amfe-flexible'
// svg
import 'virtual:svg-icons-register'
import SvgIcon from '@/components/SvgIcon/index.vue'
import VueLazyload from 'vue-lazyload'
const app = createApp(App)
app.use(VueLazyload, {
  preLoad: 1.3,
  error: './image-fail.svg',
  loading: './spin.gif',
  attempt: 1
})
// 过滤 %![]*^/'";\ 和首尾的空格
app.directive('filter-special-chars', {
  updated(el) {
    const input = el as HTMLInputElement
    // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
    if (input.getElementsByTagName('input')[0]?.value) {
      input.getElementsByTagName('input')[0].value = input
        .getElementsByTagName('input')[0]
        .value?.trim()
        ?.replace(/[%!\[\]*^\/\'\";\\\‘\’\!\“\”\；\、！\【\】\*\、]/g, '')
      input.getElementsByTagName('input')[0].dispatchEvent(new Event('input'))
    }
  }
})

// 添加按钮权限
app.directive('permission', {
  mounted(el, binding, vnode) {
    const userStore = useInfoStore()
    const routers = userStore.routers
    const { value } = binding
    if (!routers.includes(value)) {
      return (el.style.display = 'none')
    }
  }
})

app.use(router)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate) // Pinia持久化插件
app.use(pinia)
app.component('SvgIcon', SvgIcon)

app.mount('#app')
